package com.crm.controller.common;

import cn.hutool.json.JSONUtil;
import com.crm.common.result.ResultVO;
import com.crm.common.utils.StringUtils;
import com.crm.common.utils.ThreadLocalUtil;
import com.crm.service.FunctionService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 小功能集合
 *
 * @author wang_zunjing
 * @version 2025/04/18 18:10
 **/
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping()
public class FunctionController {
    private final FunctionService functionService;

    @GetMapping("/test")
    public String test() {
        Object object = ThreadLocalUtil.get();

        HashMap<String,Object> map = JSONUtil.toBean(JSONUtil.toJsonStr(object), HashMap.class);
        Long userId =  Long.valueOf(map.get("userId")+"");
        String userName = map.get("userName")+"";

        log.info("userId:{},userName:{}",userId,userName);
        return "hello world";
    }


    /**
     * 生成验证码
     */
    @GetMapping("/captchaImage")
    public HashMap<String, Object> getCode() {
        return functionService.getCodeByHuTool();
    }


    public ResultVO<Void> getSnowflake() {
        functionService.getSnowflake();
        return ResultVO.success();
    }

}
